/**
 * Copyright (C) 2011 Audit Logger Project. All rights reserved.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.auditlogger.log.log4j;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggerFactory;

/**
 * Implement the <code>org.apache.log4j.spi.LoggerFactory</code> to create
 * instances of the custom logger <code>Log4jAuditLogger</code>.
 * <br><br>
 * The advantage of having a custom Factory object is that we can control
 * how the Logger objects made
 * 
 * @author <a href="mailto:ravi.sharda@gmail.com">Ravi Sharda</a>
 */
public final class Log4jLoggerFactory implements LoggerFactory {
	
	private static final String NAME_PREFIX = "AUDITLOGGER.";
	
	private static final Log logger = LogFactory.getLog(Log4jLoggerFactory.class);
	
	@Override
	public Logger makeNewLoggerInstance(String name) {
		
		// A prefix is added in order to create a distinct logger name
		// for e.g., for separating audit logs from application logs
		Logger result = new Log4jAuditLogger(NAME_PREFIX + name);
		logger.debug("result: " + result);
		return result;
	}
}
